using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using JujuyASPNET.SourceCodeFormatter;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void cmdGenerate_Click(object sender, EventArgs e)
    {
        string InputCode = txtInputCode.Text;
        string Language = LanguageList.SelectedValue;
        bool LineNumbers = chkLineNumbers.Checked;
        bool AltColor = chkAltColor.Checked;
        bool InLineStyle = chkInLineStyle.Checked;
        string HTMLCode = SmartFormat(InputCode, Language, LineNumbers, AltColor, InLineStyle);
        lblPreview.Text = HTMLCode;
        txtCode.Text = HTMLCode;
    }


    /// <summary>
    /// SmartFormat - Takes InputCode as string and returns Generated HTML Code.
    /// </summary>
    /// <param name="InputCode"></param>
    /// <returns></returns>
    private string SmartFormat(string inputCode, string language, bool lineNumber,
        bool alternateBackground, bool inLineStyle)
    {
            string OutputHTML = string.Empty;            
            if (inputCode != string.Empty)
            {
                    SourceCode FormatCode;
                    language = language.ToUpper();
                    switch (language)
                    {
                        case "C#":
                            FormatCode = new CSharpCode();
                            break;
                        case "JavaScript":
                            FormatCode = new JavaScriptCode();
                            break;
                        case "VB":
                            FormatCode = new VBNETCode();
                            break;
                        case "ASPX":
                            FormatCode = new AspxCode();
                            break;
                        default:
                            FormatCode = new CSharpCode();
                            break;
                    }
                    FormatCode.LineNumbers = lineNumber;
                    FormatCode.AlternateColorText = alternateBackground;
                    FormatCode.InLineStyle = inLineStyle;
                    OutputHTML = FormatCode.FormatCode(inputCode);
            }
            return OutputHTML;
    }
}
